home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / IntDiffXYPanel < prev    next >
Encoding:
Text File  |  1996-01-29  |  4.4 KB  |  151 lines  |  [TEXT/IGR0]

  1. #pragma rtGlobals=1
  2.  
  3. | This procedure file creates a control panel that makes it easy to
  4. | Integrate or Differentiate XY data.
  5. |
  6. |    The code here assumes you have your data graphed using the left
  7. |    and bottom axes. If you do not choose to replace the original data, the new
  8. |    data is plotted vs the right an bottom axes.
  9. |
  10. | Wish list:
  11. |  Remember its settings through invocations
  12. |  Check for various error conditions
  13. |  Check to see on which axes  the data is plotted rather than assuming left and bottom
  14. |  Operate on a sub-range of data
  15. |  Allow for operations on data not shown in the top graph
  16. |
  17. | Larry Hutchinson 950228
  18. || Version 1.1, Larry Hutchinson 950925
  19. ||    Chagned to be Data Folder and Liberal Names aware.
  20.  
  21. Macro IntDiffXY()
  22.     NewDataFolder/O root:Packages
  23.     if( !DataFolderExists("root:Packages:WMIntDiffXY") )
  24.         NewDataFolder root:Packages:WMIntDiffXY
  25.         Variable/G root:Packages:WMIntDiffXY:gNumIntPnts= 100
  26.     endif
  27.     XYOperationPanel()
  28. End
  29.      
  30.  
  31. Function BProcXYDone(ctrlName) : ButtonControl
  32.     String ctrlName
  33.  
  34.     DoWindow/K $WinName(0, 64)
  35.     KillDataFolder root:Packages:WMIntDiffXY
  36. End
  37.  
  38.  
  39. Function BProcXYDefault(ctrlName) : ButtonControl
  40.     String ctrlName
  41.  
  42.     ControlInfo popy
  43.     Wave w= TraceNameToWaveRef("", S_Value)
  44.     NVAR np= root:Packages:WMIntDiffXY:gNumIntPnts
  45.     np= numpnts(w)*5
  46. End
  47.  
  48. Function BProcXYDoIt(ctrlName) : ButtonControl
  49.     String ctrlName
  50.     
  51.     ControlInfo popy
  52.     String yWaveName= S_Value
  53.     
  54.     ControlInfo popinterp
  55.     variable method= V_value
  56.  
  57.     ControlInfo popXYOp
  58.     variable doIntegrate= V_value==1
  59.  
  60.     ControlInfo popOpts
  61.     Variable option= V_value
  62.  
  63.     Wave wy=  TraceNameToWaveRef("", yWaveName)
  64.     Wave wx= XWaveRefFromTrace("", yWaveName)
  65.     if( (WaveExists(wy)==0) %| (WaveExists(wx)==0) )
  66.         DoAlert 0,"Can't find waves"
  67.         return 0                            || ***** error exit
  68.     endif
  69.     
  70.     yWaveName= NameOfWave(wy)
  71.     String xWaveName= NameOfWave(wx)
  72.     
  73.     String wWaveName= "int_"+yWaveName
  74.     NVAR gNumIntPnts= root:Packages:WMIntDiffXY:gNumIntPnts
  75.  
  76.     String savDF= GetDataFolder(1)                || save current data folder
  77.     SetDataFolder GetWavesDataFolder(wy, 1)    || we will ASSUME x is in same DF
  78.                                                 || we do this so Interpolate will create output in same DF
  79.  
  80.     string cmd,format = "Interpolate/N=(%d)/T=%d/Y=%s %s /X=%s"
  81.     sprintf cmd, format, gNumIntPnts, method,wWaveName, yWaveName, xWaveName
  82.     Execute cmd
  83.     Wave ww=  $wWaveName
  84.     SetDataFolder savDF                            || the rest uses wave references so CDF is irrelevant
  85.     
  86.     if(doIntegrate )
  87.         Integrate/T ww
  88.     else
  89.         Differentiate ww
  90.     endif
  91.     
  92.     do
  93.         CheckDisplayed/A $wWaveName
  94.         Variable wwIsDisplayed= V_Flag==1
  95.         if( option == 1 )
  96.             if( !wwIsDisplayed )
  97.                 AppendToGraph/R ww
  98.             endif
  99.             break
  100.         endif
  101.         if( option == 2 )
  102.             Duplicate/O ww, intxyTmp
  103.             Duplicate/O wy,ww
  104.             ww= intxyTmp(wx)
  105.             KillWaves intxyTmp
  106.             if( !wwIsDisplayed )
  107.                 AppendToGraph/R ww vs wx
  108.             endif
  109.             break
  110.         endif
  111.         if( option == 3 )
  112.             wy= ww(wx)
  113.             if( wwIsDisplayed )
  114.                 RemoveFromGraph $wWaveName    | this is a trace instance, not a wave ref
  115.             endif
  116.             KillWaves ww
  117.         endif
  118.     while(0)
  119. End
  120.  
  121. Proc XYOperationPanel()
  122.     PauseUpdate; Silent 1        | building window...
  123.     NewPanel /W=(334,151,606,343)
  124.     ModifyPanel cbRGB=(65535,54611,49151)
  125.     SetDrawLayer UserBack
  126.     SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
  127.     DrawText 72,19,"Operation:"
  128.     SetDrawEnv rounding= 20
  129.     DrawRRect 23,35,235,67
  130.     SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
  131.     DrawText 94,83,"Interpolation: "
  132.     SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
  133.     DrawText 66,138,"Options:"
  134.     SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
  135.     DrawText 67,50,"Y data:"
  136.     SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
  137.     DrawText 78,110,"# points"
  138.     PopupMenu popy,pos={73,40},size={54,19}
  139.     PopupMenu popy,mode=1,value= #"TraceNameList(\"\",\";\",1)"
  140.     PopupMenu popinterp,pos={98,74},size={66,19},mode=1,value= #"\"Linear;Spline\""
  141.     SetVariable setvarnpts,pos={84,103},size={60,15},title=" "
  142.     SetVariable setvarnpts,limits={20,10000,10},value= root:Packages:WMIntDiffXY:gNumIntPnts
  143.     Button buttonDefault,pos={147,101},size={63,20},proc=BProcXYDefault,title="Default"
  144.     PopupMenu popOpts,pos={71,128},size={161,19}
  145.     PopupMenu popOpts,mode=1,value= #"\"Evenly spaced result;At same X values;Replace Y Data\""
  146.     Button buttonDoIt,pos={26,156},size={50,20},proc=BProcXYDoIt,title="Do It"
  147.     Button buttonDone,pos={202,155},size={50,20},proc=BProcXYDone,title="Done"
  148.     PopupMenu popXYOp,pos={76,11},size={89,19}
  149.     PopupMenu popXYOp,mode=1,value= #"\"Integrate;Differentiate\""
  150. EndMacro
  151.